package com.suwenhao.test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;

/**
 * @Author:suwenhao
 * @Description: 测试
 * @Date: Created in 2020/9/26 14:56
 */
public class test {
    public static void main(String[] args) throws ParseException {
        Timer timer = new Timer();

        MyTask myTask = new MyTask();

        //立即执行
//        timer.schedule(myTask,new Date());

        //立即执行后1秒执行一次
//        timer.schedule(myTask,new Date(),1000);

        //一秒后某隔两秒执行一次
//        timer.schedule(myTask,1000,2000);

        //固定在某个时刻执行

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = sdf.parse("2020-09-26 15:12:45");
        timer.schedule(myTask, parse);

    }
}
